﻿import cn.eminia.mn.XmlLogFileV2;
import mx.utils.Delegate;
import mx.events.EventDispatcher;
class cn.eminia.mn.Sets extends cn.eminia.mn.XmlLogFileV2 {
	public var addEventListener:Function;
	private var dispatchEvent:Function;
	public var removeEventListener:Function;
	// 
	public var mnLink:Array = [];
	public var exLink:Object = {};
	public var backLink:Object = {};
	//
	public var all:Object = {};
	private static var _me:Sets;
	function Sets() {
		this.all = {};
	}
	static function getMe():Sets {
		if (Sets._me == null) {
			Sets._me = new Sets();
		}
		return Sets._me;
	}
	public function add(a:Object, b:String) {
		var tempArr:Array = new Array();
		for (var i:String in a[b]) {
			//trace(a[b][i] + " = " + i)
			tempArr.push(i);
		}
		for (var i:Number = 0; i < tempArr.length; i++) 
		{
			var id:String = tempArr[i]; 
			var c = a[b][id];
			this[b] = {};
			for (var i = 0; i<c.length; i++) {
				var o = c[i]; 
				this[b][o['id']] = o.vv;
			}
			
		}
		return;
	}
	public function addCombo(a, b) {
		this.all[b] = [];
		//
		for (i in a[b]) {
			if (i != 'g') {
				this.all[b][i] = a[b][i];
			}
		}
		//
		var g = a[b].g;
		for (var i = 0; i<g.length; i++) {
			var o = g[i];
			this.all[b][i] = o.value;
			if (o.select == '1') {
				this.all[b].initData = o.value;
				this.all[b].initID = i;
			}
		}
		// 
		return;
	}
	static function doValue(a, b) {
		for (var i = 0; i<a.length; i++) {
			var o = a[i];
			b[o.id] = o.clr.split('|');
		}
	}
	static function arr_doValue(a, b) {
		b = [];
		for (var i = 0; i<a.length; i++) {
			var o = a[i];
			b[i] = o.age;
		}
	}
	public function load(url:String):Void {
		var xml:XML = new XML();
		xml.ignoreWhite = true;
		EventDispatcher.initialize(this);
		xml.onLoad = Delegate.create(this, function (success) {
			if (success) {
				//isLoaded = true;
				var obj =  XmlLogFileV2.getChildAsObject(xml.childNodes[0]);
				//主菜单 
				this.mnLink = [];
				this.mnLink[0] = null;
				this.mnLink = this.mnLink.concat(obj.mnLink.link);
				//辅助菜单 
				for (var i = 0; i<obj.backLink.link.length; i++) {
					var o = obj.backLink.link[i];
					this.backLink[o.id] = o.url;
				}
				// 
				//addCombo(obj, 'Age');
				add(obj, 'siteInit');
				add(obj, 'gameInit');
				add(obj, 'AlertSys'); 
				//
				dispatchEvent({type:"init", target:obj});
			} else {
				throw new Error('Config Link Failure');
			}
		});
		xml.load(url);
	}
}
